package net.babypai.utils;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class PicDownloader {
	public static Bitmap downloadBitmap(String urlStr) {
    	InputStream is = null;
    	try {
    		is = getInputStreamFromUrl(urlStr);
    		
    	} catch (MalformedURLException e) {
    		e.printStackTrace();
    	} catch (IOException e) {
    		e.printStackTrace();
    	}
    	
    	Bitmap bitmap = BitmapFactory.decodeStream(is);
    	return bitmap;
    	
    }
    
    public static InputStream getInputStreamFromUrl(String urlStr)
		throws MalformedURLException, IOException {
    	URL url = new URL(urlStr);
    	HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    	InputStream inputStream = urlConn.getInputStream();
    	return inputStream;
    }
}
